package com.example.autooperation.controller;

import com.example.autooperation.util.JWTUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api")
public class LoginController {

    @PostMapping("/login")
    public String login(@RequestBody Map<String, String> credentials) {
        // 简单的用户名密码验证，实际应用中应该从数据库查询用户信息
        String username = credentials.get("username");
        String password = credentials.get("password");
        if ("admin".equals(username) && "password".equals(password)) {
            return JWTUtil.createToken(username);
        } else {
            return "Invalid credentials";
        }
    }
} 